﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Frogism.Domain
{
    public class UserManager
    {
        public Core.User GetUser(string username)
        {
            return new Data._2.UserRepository().GetByName(username);
        }
        public string HashHexString(string instring)
        {
            var hashbytes = ComputeHash(instring);



                  StringBuilder sb = new StringBuilder();
                  for (int i = 0; i < hashbytes.Length; i++)
                  {
                      sb.Append(hashbytes[i].ToString("X2").ToLower());
                  }
                  return sb.ToString();
        }

        private byte[] ComputeHash(string plainText)
        {
            // Convert plain text into a byte array.
            byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

 
            // Because we support multiple hashing algorithms, we must define
            // hash object as a common (abstract) base class. We will specify the
            // actual hashing algorithm class later during object creation.
            HashAlgorithm hash;

            hash = new SHA256Managed();
   
            // Compute hash value of our plain text with appended salt.
            byte[] hashBytes = hash.ComputeHash(plainTextBytes);


            // Convert result into a base64-encoded string.
            string hashValue = Convert.ToBase64String(hashBytes);

            // Return the result.
            return hashBytes;
        }
    }
}
